﻿CREATE PROCEDURE [maint].[InsertDeviceHeader]
@DeviceName [sysname], @TempHeaderTableName NVARCHAR (36)
AS
BEGIN
	DECLARE @RC int;
	SET @RC = 0;
	
	DELETE [maint].[DeviceHeaders]
	WHERE ([DeviceName] = @DeviceName);	
	
	DECLARE @InsertStatement nvarchar(4000);
	SET @InsertStatement = N'INSERT [maint].[DeviceHeaders] SELECT ''' + @DeviceName + N''',* FROM ' + @TempHeaderTableName;
	EXEC @RC = sp_executesql @InsertStatement;

	RETURN(@RC);
END